<template>
  <cfg-table
    :ref="ref"
    :config="config"
    :loading="loading"
    :data="data"
    :columns="columns"
    :additionalAction="additionalAction"
    :pageSizeOpts="pageSizeOpts"
    :pageNavigation="pageNavigation"
    :queryFormItem="queryFormItem"
    :collapseFormItem="collapseFormItem"
    :btnShowFun="btnShowFun"
    :rowbgc="rowbgc"
    :tableStyle="{ overflow: 'hidden !important' }"
    @loadPage="loadPage"
    @handleEdit="handleEdit"
    @handleDelete="handleDelete"
    @handleDetail="handleDetail"
    @handleClick="handleClick"
    @handleDbClick="handleDbClick"
    @handleCreate="handleCreate"
    @handleDeleteMultiple="handleDeleteMultiple"
    @handleSearch="handleSearch"
    @handleReset="handleReset"
    @handleChangePage="handleChangePage"
  ></cfg-table>
</template>

<script>
export default {
  name: "pg-table",
  components: {},
  inject: ["anc"],
  data() {
    return {
      ref: "leftTable",
      loading: false,
      pageNavigation: {
        total: 0,
        pageSize: 10,
        pageNumber: 1,
      },
      maintainCyleOptions: [
        { value: "day", label: "日" },
        { value: "week", label: "周" },
        { value: "month", label: "月" },
        { value: "year", label: "年" },
      ],
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    config() {
      return {
        search: true,
        addButton: true,
        batchDeleteButton: true,
        downloadIcon: true,
        uploadIcon: false,
        uploadUrl: "/",
        tableSizeIcon: false,
        fullscreenIcon: false,
        refreshIcon: true,
        columnSettingIcon: true,
        action: true, // 操作
        checkColumnDisabled: false,
        additionalAction: false, // 新增自定义
      };
    },
    columns() {
      return [
        {
          key: "sf_name",
          title: "班组名称",
          minWidth: 200,
          align: "center",
          show: true,
          config: { type: "text", disabled: this.onlyRead },
        },
       
      
      ];
    },

    additionalAction() {
      return {
        key: "additionalAction",
        title: "附加操作",
        slot: "additionalAction",
        width: 200,
        fixed: "right",
        align: "center",
        show: true,
        buttons: [
          {
            title: "abc",
            color: "red",
            event: (row, index) => console.log(row),
          },
          { title: "abc2", event: (row, index) => console.log(row) },
        ],
      };
    },
    pageSizeOpts() {
      return [10, 30, 50, 100];
    },
    // pageNavigation() {
    //   return { total: 0, pageSize: 10, pageNumber: 1 };
    // },
    queryFormItem() {},
    collapseFormItem() {
      return [{ title: "计划名称", key: "sf_name", config: { type: "text" } }];
    },
    btnShowFun() {
      return function () {
        return true;
      };
    },
    rowbgc() {
      return "red";
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
      this.loadPage(this.pageNavigation, {});
    });
  },
  methods: {
    loadPage(pageNavigation, filter, orderBy = "") {
      this.anc.leftLoadPage(this.pageNavigation, filter, "", orderBy, false);
    },
    handleDelete(row, index) {
      this.anc.leftTableDelete(row, index);
    },
    handleEdit(row, index) {
      // if (JSON.parse(row.sf_planMaintainDate).length >= 0) {
      //   row.sf_planMaintainDate = JSON.parse(row.sf_planMaintainDate);
      // }
      this.anc.leftTableEdit(row, index);
    },
    handleDetail(row, index) {
      this.anc.leftTableDetail(row, index);
    },
    handleCreate() {
      this.anc.leftTableCreate();
    },
    handleClick(row, index) {
      this.anc.leftClickItem = row;
      this.anc.leftClick(row, index);
    },
    handleDbClick(row, index) {},

    handleDeleteMultiple(selection) {
      this.anc.leftTableDeleteMultiple(selection);
    },
    handleReset() {
      this.pageNavigation.pageNumber = 1;
      this.anc.leftLoadPage(this.pageNavigation, {}, "", "", false);
    },
    handleSearch(filter) {
      this.pageNavigation.pageNumber = 1;
      this.anc.leftLoadPage(this.pageNavigation, filter, "", '', false);
    },
    handleChangePage() {},
   
  },
};
</script>
<style scoped></style>
